package com.kk.netty.nio.file;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

public class TestRemoveFile {
    public static void main(String[] args) throws IOException {
        Path path = Paths.get ("j:\\test");
        Files.walkFileTree (path,new SimpleFileVisitor<Path> (){
            // 先删除文件
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Files.delete (file);
                return super.visitFile (file, attrs);
            }

            // 再删除目录
            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                Files.delete (dir);
                return super.postVisitDirectory (dir, exc);
            }
        });
    }
}
